package com.epam.OOP.transport;

import com.epam.OOP.cargo.Cargo;
import com.epam.OOP.utils.BundlesReader;
import com.epam.OOP.utils.Validator;

import java.io.UnsupportedEncodingException;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created with IntelliJ IDEA.
 * User: Yelena_M
 * Date: 04.08.13
 * Time: 23:43
 * To change this template use File | Settings | File Templates.
 */
public class Transport {

    private String id;
    private String mark;
    private TransportType transportType;
    private Set<Cargo> cargo = new TreeSet<Cargo>();

    public Transport(){

    }

    public Transport(String id, String mark, TransportType transportType, Set<Cargo> cargo) {
        this.id = id;
        this.mark = mark;
        this.transportType = transportType;
        this.cargo = cargo;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMark() {
        return mark;
    }

    public void setMark(String mark) {
        this.mark = mark;
    }

    public TransportType getTransportType() {
        return transportType;
    }

    public void setTransportType(TransportType transportType) {
        this.transportType = transportType;
    }

    public Set<Cargo> getCargo() {
        return cargo;
    }

    public void setCargo(Set<Cargo> cargo) {
        this.cargo = cargo;
    }

    @Override
    public String toString() {
        return "Transport{" +
                "id='" + id + '\'' +
                ", mark='" + mark + '\'' +
                ", transportType=" + transportType +
                ", cargo=" + cargo +
                '}';
    }

    public static int volumeCount(int lengthBody, int widthBody, int heightBody) throws UnsupportedEncodingException {
        int volume = 0;

        if ((!Validator.checkDataForDigital(String.valueOf(lengthBody))) &&
            (!Validator.checkDataForDigital(String.valueOf(widthBody))) &&
            (!Validator.checkDataForDigital(String.valueOf(heightBody)))) {
                BundlesReader.read("MessageWrongData");
                System.exit(0);
        } else  {
            volume =  lengthBody * widthBody * heightBody;
        }
        return volume;
    }

    public static void loadCargo(int cargoVolume, int transportVolume) throws UnsupportedEncodingException {
        if (cargoVolume > transportVolume) {
            System.out.println(BundlesReader.read("MessageTransportDidNotLoad") + " " + cargoVolume);
        } else {
            System.out.println(BundlesReader.read("MessageTransportLoad"));
        }
    }
}
